#define _CRT_SECURE_NO_WARNINGS 1
#include<vector>
#include<queue>
using namespace std;
int maxAreaOfIsland(vector<vector<int>>& grid) {
    int max = 0;
    for (int i = 0; i < grid.size(); i++)
    {
        for (int j = 0; j < grid[0].size(); j++)
        {
            if (grid[i][j] == 1)
            {
                int num = bfs(grid, i, j);
                max = max > num ? max : num;
            }
        }
    }
    return max;
}


int bfs(vector<vector<int>>& v, int a, int b) {
    int count = 0;
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    queue<pair<int, int>> q;
    q.push({ a,b });
    while (q.size())
    {
        auto p = q.front();
        int m = p.first;
        int n = p.second;
        q.pop();
        v[m][n] = 0;
        count++;
        for (int i = 0; i < 4; i++)
        {
            int x = m + dx[i];
            int y = n + dy[i];
            if (x >= 0 && y >= 0 && x < v.size() && y < v[0].size() && v[x][y] == 1)
            {
                q.push({ x,y });
                v[x][y] = 0;
            }
        }
    }
    return count;
}